import { BasicColumn } from '/@/components/Table'
import { FormSchema } from '/@/components/Table'
import { h } from 'vue'
import { Tag } from 'ant-design-vue'

export const columns: BasicColumn[] = [
  {
    title: '分类名称',
    dataIndex: 'name',
    width: 200,
    align: 'left',
    // fixed: 'left',
  },
  {
    title: '分类ID',
    dataIndex: 'catId',
    width: 80,
  },
  {
    title: 'Highest Rank',
    dataIndex: 'highestRank',
    width: 80,
  },
  {
    title: '子分类个数',
    dataIndex: 'children_num',
    width: 80,
  },
  {
    title: 'Lowest Rank',
    dataIndex: 'lowestRank',
    width: 80,
  },
  {
    title: 'Is Browse Node',
    dataIndex: 'isBrowseNode',
    width: 120,
    customRender: ({ record }) => {
      const isBrowseNode = record.isBrowseNode
      const enable = ~~isBrowseNode === 1
      const color = enable ? 'green' : 'red'
      const text = enable ? '是' : '否'
      return h(Tag, { color: color }, () => text)
    },
  },
  {
    title: '产品数量',
    dataIndex: 'productCount',
    width: 80,
  },
  {
    title: '获取时间',
    dataIndex: 'created_at',
    width: 120,
    customRender: ({ record }) => {
      const created_at = record.created_at * 1000
      const date = new Date(created_at)
      const y = date.getFullYear()
      let MM = (date.getMonth() + 1) as number
      MM = MM < 10 ? (('0' + MM) as unknown as number) : MM
      let d = date.getDate()
      d = d < 10 ? (('0' + d) as unknown as number) : d
      let h = date.getHours()
      h = h < 10 ? (('0' + h) as unknown as number) : h
      let m = date.getMinutes()
      m = m < 10 ? (('0' + m) as unknown as number) : m
      let s = date.getSeconds()
      s = s < 10 ? (('0' + s) as unknown as number) : s
      return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
    },
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: 'domainId',
    label: '国家',
    component: 'Select',
    componentProps: {
      options: [
        { label: 'US', value: 1 },
        { label: 'GB', value: 2 },
        { label: 'DE', value: 3 },
        { label: 'FR', value: 4 },
        { label: 'JP', value: 5 },
        { label: 'CA', value: 6 },
        { label: 'RESERVED2', value: 7 },
        { label: 'IT', value: 8 },
        { label: 'ES', value: 9 },
        { label: 'IN', value: 10 },
        { label: 'MX', value: 11 },
        { label: 'BR', value: 12 },
      ],
    },
    colProps: { span: 6 },
  },
]
